package com.qf.serviceimpl;

import com.qf.constant.CacheConstants;
import com.qf.constant.StrategyConstants;
import com.qf.feign.CacheFeign;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 黑名单过滤策略
 *
 * @author Ypl
 * @version V1.0
 * @Project OctoberAndNovember
 * @Package com.qf.serviceimpl
 * @Description:
 * @Date 2022/11/10 10:44
 */
@SuppressWarnings("all")
@Service(value = "black")
@Slf4j
public class BlackFilterServiceImpl implements FilterChainService {

    @Autowired
    CacheFeign cacheFeign;

    @Autowired
    PushMsgUtil pushMsgUtil;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("【黑名单策略】 开始执行");
        //获取手机号
        String destMobile = standardSubmit.getDestMobile();
        //去redis中去拿取数据
        String result = cacheFeign.get(CacheConstants.CACHE_PREFIX_BLACK + destMobile);

        if(result != null ){
            //将日志存入MQ
            pushMsgUtil.sendLog(standardSubmit, StrategyConstants.STRATEGY_ERROR_BLACK);
            pushMsgUtil.pushReport(standardSubmit,StrategyConstants.STRATEGY_ERROR_BLACK);
            return false ;
        }
        log.info("【黑名单策略】 执行结束");
        return true;
    }
}
